﻿using System;
using System.Web;
using System.Web.UI;
using MyHealthByDesign.Helper;

namespace MyHealthByDesign
{
    public partial class ForgotPassword : System.Web.UI.Page
    {
        Domain.Domain domain = new Domain.Domain();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string email = txtEmail.Text;

            if(domain.SendEmail(email))
            {
                txtEmail.Visible = false;
                btnSubmit.Visible = false;
                lblEmail.Visible = false;
                lblRequired.Visible = false;
                lblSuccess.Visible = true;
                hplnkLogin.Visible = true;
            }
            else
            {
                DisplayErrorMessage("Error! Could not find password for entered email address!");
            }
        }

        public static void DisplayErrorMessage(string message)
        {
            var currentPage = HttpContext.Current.Handler as Page;
            if (currentPage != null) currentPage.Validators.Add(new ValidationError(message));
        }
    }
}